import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.FileInputStream;

public class StartTest {

    public static void main(String[] args) throws Exception {

        String inputFile = Tools.getResourcePath("vars2.cymbol");

        var stream = new FileInputStream(inputFile);
        var input = new ANTLRInputStream(stream);
        var lexer = new CymbolLexer(input);// 词法分析器，将输入文本转换为词法符号
        var tokens = new CommonTokenStream(lexer);// 词法符号流
        var parser = new CymbolParser(tokens);// 语法分析器

        //始语法分析的过程，注意这里的起始位置是从file这个结点开始的
        var tree = parser.file();

        var walker = new ParseTreeWalker();// 新建一个标准遍历器
        var listener1 = new DefPhase();
        walker.walk(listener1, tree);

        var listener2 = new RefPhase(listener1.scopes);
        walker.walk(listener2, tree);
    }
}
